package org.example.dbcompare.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wuyong
 * @date 2025/10/31
 */
public class ExportDataSqlResult {
    /**
     * 生成的 INSERT 语句
     */
    private List<String> insertSqls = new ArrayList<>();

    /**
     * 所有语句汇总
     */
    private List<String> allSqls = new ArrayList<>();

    /**
     * 计数
     */
    private int insertCount;

    public List<String> getInsertSqls() {
        return insertSqls;
    }

    public List<String> getAllSqls() {
        return allSqls;
    }

    public int getInsertCount() {
        return insertCount;
    }

    public void addInsertSql(String sql) {
        if (sql == null || sql.trim().isEmpty()) {
            return;
        }
        insertSqls.add(sql);
        allSqls.add(sql);
        insertCount++;
    }
    public String getFullSqlScript(){
        if (allSqls == null || allSqls.isEmpty()) {
            return "";
        }
        String lineSep = System.lineSeparator();
        StringBuilder sb = new StringBuilder();
        sb.append("-- Generated SQL inserts").append(lineSep);
        sb.append("-- total inserts: ").append(insertCount).append(lineSep);
        for (String sql : allSqls) {
            sb.append(sql);
            if (!sql.trim().endsWith(";")) {
                sb.append(";");
            }
            sb.append(lineSep);
        }
        return sb.toString();
    }
}
